import axiosInstance from './axios'
import { RequestEnum, ContentTypeEnum } from '@/enums/httpEnum'

export const request = {
  /**
   * @description -get请求
   * @param url -请求地址
   * @param params -请求参数
   * @return  Promise
   */
  get(url: string, params?: object) {
    return axiosInstance({
      url,
      method: RequestEnum.GET,
      params
    })
  },

  /**
   * @description -post请求
   * @param url -请求地址
   * @param params -请求参数
   * @param headersType -请求配置
   * @return  Promise
   */
  post(url: string, params?: object, headersType?: string) {
    return axiosInstance({
      url,
      method: RequestEnum.POST,
      data: params,
      headers: {
        'Content-Type': headersType || ContentTypeEnum.JSON
      }
    })
  },

  patch(url: string, params?: object, headersType?: string) {
    return axiosInstance({
      url,
      method: RequestEnum.PATCH,
      data: params,
      headers: {
        'Content-Type': headersType || ContentTypeEnum.JSON
      }
    })
  },

  put(url: string, params?: object, headersType?: ContentTypeEnum) {
    return axiosInstance({
      url,
      method: RequestEnum.PUT,
      data: params,
      headers: {
        'Content-Type': headersType || ContentTypeEnum.JSON
      }
    })
  },

  delete(url: string, params?: object) {
    return axiosInstance({
      url,
      method: RequestEnum.DELETE,
      params
    })
  }
}